﻿var music = new Audio();
var musics = ["MC大科-小可爱","纯音乐-白噪音","纯音乐-莫扎特催眠曲g大调钢琴","纯音乐-轻微海浪声","纯音乐-时钟的滴答声","纯音乐-胎教音乐","王继阳-坠入爱",
"纯音乐-莫扎特催眠曲g大调钢琴","纯音乐-时钟的滴答声","王继阳-坠入爱","纯音乐-时钟的滴答声","纯音乐-莫扎特催眠曲g大调钢琴"];
var mxs=["tou1","tou2","tou3","tou4"];
var i = 0;
window.onload = function(){
    var lis = document.getElementsByClassName("mulu");
    console.log(lis);
    for(var i=0;i<lis.length;i++){
        var m = lis[i];
        m.index = i;
        m.onclick = function(){
            i = this.index;
            music.src="music/"+this.innerText+".mp3";
            music.play();
            foot.style.display = "flex";
           gg.innerHTML = this.firstElementChild.lastElementChild.innerHTML;
            zz.innerHTML = this.firstElementChild.firstElementChild.innerHTML;
            mx.src="image/"+mxs[(Math.floor(Math.random()*4))]+".jpg";
            cbtn.src = "image/1.png";
           
        };
       
    }
  

    cbtn.onclick = function() {
        //img是按钮图片
        var img = this.src;
        //如果按钮图片是"暂停"，则执行暂停操作
        if (img == this.src) {
            music.pause();
            this.src = "image/3.png";
        }
        if (img == this.src) {
            //如果按钮不是"暂停"，则执行播放操作
            music.play();
            this.src = "image/1.png";
           
        }

    };



      nbtn.onclick = function(){
        //如果现在播放器播放的是最后一首歌
        if(i>=musics.length-1){
          //则切到第一首歌
          i = 0;
        }else{
          //否则切到下一首歌
          i++;
        }
        gg.innerHTML =lis[i].firstElementChild.lastElementChild.innerHTML;
        zz.innerHTML =lis[i].firstElementChild.firstElementChild.innerHTML;
        music.src = "music/"+musics[i] + ".mp3";
        music.play(); 
        cbtn.src="image/1.png";
        mx.src="image/"+mxs[(Math.floor(Math.random()*4))]+".jpg";
    };

    //下载弹框
    var fugans = document.getElementsByClassName("xiazai");
    for(var i=0;i<fugans.length;i++){
        var j = fugans[i];
        j.index = i;
        j.onclick = function(){
            i = this.index;
            cover.style.display = "block";
            tishi.style.display="block";
        };
    }
    quxiao.onclick = function(){
        cover.style.display = "none";
        tishi.style.display="none";
    }
  
    kehuduan.onclick = function(){
        this.href="http://m.kugou.com/plist/list/202554";
    }
    dbtn.onclick = function(){
        cover.style.display = "block";
        tishi.style.display="block";
    }
}